package com.itheima.article.listener;

import com.itheima.article.pojo.ApArticleConfig;
import com.itheima.article.service.ApArticleConfigService;
import com.itheima.common.constants.BusinessConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class ApArticleConfigListener {


    @Autowired
    private ApArticleConfigService apArticleConfigService;

    /**
     * 文章上下架同步
     * @param record
     */
    @KafkaListener(topics = BusinessConstants.MqConstants.WM_NEWS_DOWN_OR_UP_TOPIC)
    public void upOrDown(ConsumerRecord<String,String> record){
        String topic = record.topic();
        long offset = record.offset();
        int partition = record.partition();
        String value = record.value();
        log.info("文章上下架同步————开始：p={},t={},o={},v={}",partition,topic,offset,value);
        apArticleConfigService.upOrDown(value);
        log.info("文章上下架同步————结束：p={},t={},o={},v={}",partition,topic,offset,value);
    }
}
